< previous page page_313 next page >

Page 313
Julia Sets
To draw a Mandelbrot set, you evaluate the sequence of values:
e10a6a0a59f035e870d90cca05b85fce.gif
Zn = Zn-12 + C
where Zn and C are complex numbers. For the Mandelbrot set, you start with Zn = 0 and use the coordinates of the pixels in the image to give you the value of C. For each value of C, you calculate the series of Zn values to see if the magnitude of the values tends toward infinity.
You use the same equation to create Julia sets. There are only two differences between drawing the Mandelbrot set and drawing Julia sets. The first difference is in how you select Z0 and C. To draw a Julia set, you pick some constant value for C. You then use the coordinates of the pixels in the image to get the value Z0.
The second difference is in selecting colors for the pixels. The Mandelbrot program sets a pixel's color based on how quickly the magnitude of Zn exceeds 2. A Julia set program sets a pixel's color based on how large its magnitude is if it does not exceed 2 after a certain number of iterations. If the magnitude does exceed 2, the pixel is given a default background color.
The following code shows a Julia set drawing routine.
e10a6a0a59f035e870d90cca05b85fce.gif
' Draw the Mandelbrot set.
Private Sub DrawJulia()
' Work until the magnitude squared > 4.
Const MAX_MAG_SQUARED = 4

Dim pixels() As RGBTriplet
Dim bits_per_pixel As Integer
Dim wid As Long
Dim hgt As Long
Dim clr As Long
Dim color As Long
Dim i As Integer
Dim j As Integer
Dim dReaZO As Double
Dim dImaZO As Double
Dim ReaZO As Double
Dim ImaZO As Double
Dim ReaZ As Double
Dim ImaZ As Double
Dim ReaZ2 As Double
Dim ImaZ2 As Double
Dim r As Integer
Dim b As Integer
Dim g As Integer

    picCanvas.Line (0, 0)-(picCanvas.ScaleWidth, _

 
< previous page page_313 next page >